home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-11-05 | 3.6 KB | 139 lines | [TEXT/CWIE] |
- /*************************************************************************************
-
- TEnemySprite.cp
-
- This is the class used to represent the enemy ship in the game. Eventually,
- one ship class will represent both friendly and enemy ships, since the only
- major difference is the keyset. A computer controlled ship could be
- different.
-
-
- Author: Timothy Carroll
- Apple Developer Technical Support
- timc@apple.com
-
- Modification History:
-
- 1/23/97 TMC Added include for Moofwars.h so that MrC will compile
- 8/15/96 TMC Initial Release
-
- Copyright © 1996, 1997 Apple Computer, Inc., All Rights Reserved
-
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
-
- #include "Moofwars.h"
- #include "TEnemySprite.h"
- #include "TShotSprite.h"
-
-
-
- TEnemySprite::TEnemySprite (TEnemySpriteData *data):
- TSprite((TSpriteData *) data)
- {
- fRotateInterval = data->rotateInterval;
- fRotateValue = 0;
- fShotInterval = data->shotInterval;
- fShotValue = 0;
- fShotsGroup = data->shotsGroup;
- }
-
-
- TEnemySprite::~TEnemySprite (void)
- {
- }
-
- void
- TEnemySprite::ProcessSprite ()
- {
- // The enemy can thrust in either direction
- if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyThrustForward))
- {
- fVelocityY -= gSinLookup [fFace] >> 1;
- fVelocityX -= gCosLookup [fFace] >> 1;
- }
-
- if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyThrustBackward))
- {
- fVelocityY += gSinLookup [fFace] >> 1;
- fVelocityX += gCosLookup [fFace] >> 1;
- }
-
- // Fire a shot
- if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyFireShots) && fShotValue == 0)
- {
- TShotSpriteData shotData;
- TShotSprite *shot;
- int index;
-
- // Delay for next set of shots
- fShotValue = fShotInterval;
-
- shotData.spriteData.spriteType = TShotSprite::kSpriteType;
- shotData.spriteData.visibility = kVisible;
- shotData.spriteData.face = 1;
- shotData.spriteData.collectionID = 1001;
- shotData.spriteData.preloadedCollection = NULL;
- shotData.duration = 60;
-
- index = fFace;
-
- shotData.spriteData.initialX = fCoordX - 60*gCosLookup [index];
- shotData.spriteData.initialY = fCoordY - 60*gSinLookup [index];
- shotData.spriteData.initialXVelocity = fVelocityX - 30*gCosLookup[index];
- shotData.spriteData.initialYVelocity = fVelocityY - 30*gSinLookup[index];
- shot = new TShotSprite (&shotData);
- shot->AddToGroup (fShotsGroup);
-
- }
-
-
- // Rotate right
- if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyRotateRight) && fRotateValue == 0)
- {
- fFace = (fFace+1) % 48;
- fRotateValue = fRotateInterval;
- }
-
-
- // Rotate left
- if (CheckKey ((unsigned char *) &gCommandKeys, kEnemyRotateLeft) && fRotateValue == 0)
- {
- fFace = (fFace+47) % 48;
- fRotateValue = fRotateInterval;
- }
-
-
- // Adjust our intervals
- if (fRotateValue > 0)
- fRotateValue--;
-
- if (fShotValue > 0)
- fShotValue--;
-
- TSprite::ProcessSprite();
- TSprite::Bounce (&gWorldBounds);
- }
-
-
- void
- TEnemySprite::Collision (TSprite *theSprite)
- {
- #if qUsingSound
- if (gPlayingSound)
- HY_PlaySoundHandle (2, gSounds[3], NULL, 0, false);
- #endif
- // We take on some of the velocity of the shot.
- TShotSprite *theTarget = (TShotSprite *) theSprite;
-
- //this->fCurVelocityX += theTarget->GetXVelocity() >> 9;
- //this->fCurVelocityY += theTarget->GetYVelocity() >> 9;
- }